﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using AccessModel;
using DBUtility;
using MySql.Data.MySqlClient;
using System.Data;

namespace AccessDAL
{
    public class EmployeesDAL
    {
        public static Employees CheckUserInfo(string _userName, string _passWord)
        {
            string sql = "SELECT * FROM EMPLOYEES WHERE NAME='" + _userName + "' AND PASSWORD='" + _passWord + "'";
            Employees emplyee = new Employees();

            try
            {

                MySqlDataReader dr = DBUtility.MySqlHelper.ExecuteReader(sql, null);
                while (dr.Read())
                {
                    emplyee.id = Convert.ToInt32(dr["id"].ToString());
                    emplyee.name = dr["name"].ToString();
                    emplyee.password = dr["password"].ToString();
                    emplyee.age = Convert.ToInt32(dr["age"].ToString());
                    emplyee.email = dr["email"].ToString();
                }
                dr.Dispose();
                dr.Close();
            }
            catch (Exception e)
            {
                throw e;

            }

            return emplyee;
        }

        public static bool CheckUserIsExits(string _userName)
        {
            string sql = "SELECT * FROM EMPLOYEES WHERE NAME='" + _userName + "'" ;
            if (DBUtility.MySqlHelper.GetRowsNum(sql)==0)
            {
                return false;                
            }
            return true;
        }
    }
}
